#include "key.h"

void Key_Init(Key_struct* key)
{
    key->Current_sta = release;
    key->key_event = idle;
}

void Key_Status_FSM(Key_struct *key)
{
    key->Current_sta = (enum key_status)HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0); // 上拉输入

    KEY_FSM.Status[KEY_FSM.Now_Status_Serial].Time++;
    switch (KEY_FSM.Now_Status_Serial)
    {
    case 0:
        /*code*/
        if (key->Current_sta == pressed)
            if (KEY_FSM.Status[KEY_FSM.Now_Status_Serial].Time > 20)
                {
                    while (key->Current_sta == pressed);
                    Set_Status(&KEY_FSM, 1);
                }
        break;

    case 1:
        /*code*/
        if (KEY_FSM.Status[KEY_FSM.Now_Status_Serial].Time > 20)
        {
            if (key->Last_key_event == idle)
                key->key_event = set_yaw_angle_1;
            else if (key->Last_key_event == set_yaw_angle_1)
                key->key_event = set_yaw_angle_2;
            else if (key->Last_key_event == set_yaw_angle_2)
                key->key_event = idle;
        }
        if(key->Last_key_event != key->key_event)
            Set_Status(&KEY_FSM,0);
        break;
    }
    key->Last_key_event = key->key_event;
}
